<?php
	session_start();


	include("/var/www/html/vivencias/conexaoBD.php");

	//Variáveis
	$idPost = $_GET['idPost'];
	$ler    = $_GET['ler'];

	//Dados do Post
	$query = "SELECT titulo, post, dataHora, idBlog FROM blogsPosts WHERE idPost=".$idPost;
	if(is_resource($resultado = mysql_query($query, $conexao))){
		$objeto     = mysql_fetch_object($resultado);
		$idBlog	    = $objeto->idBlog;
		$tituloPost = $objeto->titulo;
		$post       = substr($objeto->post,0,100) . "...";
		$dataHora   = explode(" ",$objeto->dataHora);
		$data       = ereg_replace("([0-9]{2}([0-9]{2})?)[/.-]([01]?[0-9])[/.-]([0123]?[0-9])","\\4-\\3-\\1",$dataHora[0]);
		$hora       = ereg_replace("([0-9]{2}([0-9]{2})?)[/.-]([01]?[0-9])[/.-]([0123]?[0-9])","\\4-\\3-\\1",$dataHora[1]);
	}else{
		die("Houve um erro ao carregar os dados do post. Se o erro persistir, por favor, entre em contato com o Suporte Técnico."); 
	} 
	
	//Dados do Blog
	$query = "SELECT titulo FROM blogs WHERE idBlog=".$idBlog;
	if(is_resource($resultado = mysql_query($query, $conexao))){
		$objeto = mysql_fetch_object($resultado);
		$tituloBlog = $objeto->titulo;
	}else{
		$tituloBlog = "Houve um erro ao carregar o título do blog."; 
	} 
	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Experi&ecirc;ncias do Processo de Adoecimento</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="vivencias.css" rel="stylesheet" type="text/css">
</head>

<body>
<div align="center"> 
  <table width="750" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr> 
                  <td width="10%" align="left" valign="top"><img src="imagens/logo.jpg" width="66" height="53"></td>
                  <td width="90%"><img src="imagens/tit1.jpg" width="554" height="34"></td>
                </tr>
              </table></td>
          </tr>
          <tr> 
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr align="left" valign="middle"> 
                  <td width="33%" class="nomecurso">&nbsp;</td>
                  <td width="60%" class="miudo">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr align="left" valign="middle"> 
                  <td colspan="2" class="miudo">&nbsp;</td>
                  <td width="1%">&nbsp;</td>
                  <td width="1%">&nbsp;</td>
                  <td width="5%">&nbsp;</td>
                </tr>
              </table></td>
          </tr>
          <tr> 
            <td align="center" valign="top">
			<table width="70%" border="0" cellpadding="5" cellspacing="1">
                <tr> 
                  <td bgcolor="53a3aa" class="titprincipal"><span class="ativo"><strong><?php echo $tituloBlog;?></strong></span></td>
                </tr>
                <tr> 
                  <td align="center" valign="middle" class="texto2"><table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                      <tr bgcolor="99e2c4" class="texttab"> 
                        <td width="43%" align="right" valign="middle" bgcolor="9dd1d7" class="texto"><div align="left"><span class="ativo">Comente</span></div></td>
                      </tr>
                      <tr bgcolor="99e2c4" class="texttab"> 
                        <td align="right" valign="middle" bgcolor="9dd1d7" class="texto"> 
                          <div align="left"><span class="ativomenor"><?php echo $tituloPost;?></span><br>
                            <?php echo $post;?><br><br>
                            <span class="miudo"><?php echo $data . " " .$hora;?></span> </div></td>
                      </tr>
                    </table></td>
                </tr>
		<form action="insereBlogPostComentario.php" method="post">
		<input type="hidden" name="idPost" value="<?php echo $idPost;?>">    
		<?php if($ler){?>
			<input type="hidden" name="ler" value="1">    
		<?php } ?>            
		<tr> 
                  <td class="titvermelho"><table width="100%" border="0" cellspacing="1" cellpadding="5">
                      <tr bgcolor="d3f2f5" class="texttab"> 
                        <td align="right" valign="top"> <div align="left" class="texto"></div>
                          <div align="left"><span class="ativomenor">Seu coment&aacute;rio:</span></div></td>
                        <td class="texto"> 
				<textarea name="comentario" cols="40" rows="7"></textarea> 
                        </td>
                      </tr>
                      <tr bgcolor="F5FEFF" class="texttab"> 
                        <td valign="middle">&nbsp;</td>
                        <td valign="middle" class="texto"><input type="submit" name="btSubmit" value="Enviar"></td>
                      </tr>
                    </table></td>
                </tr>
		</form>
              </table>
              <p align="center">&nbsp;</p></td>
          </tr>
        </table></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</div>
</body>
</html>
